/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 2e5;

int ecnt;
int heads[maxn + 1];

struct Edge {
  int v, nxt;
} e[maxn * 2 + 2];

inline void add(int u, int v) {
  e[++ecnt].v = v, e[ecnt].nxt = heads[u], heads[u] = ecnt;
}

int dfs(int u, int fa, int tag) {
  int ans = 0;
  for (int i = heads[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa) {
      continue;
    }
    ans = std::max(ans, dfs(v, u, i) + (tag > i));
  }
  return ans;
}

// bool vis[maxn + 1];

void solve() {
  int n;
  cin >> n;
  ecnt = 0;
  for (int i = 1; i <= n; ++i) {
    heads[i] = 0;
  }
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    add(u, v);
    add(v, u);
  }
  cout << dfs(1, 1, ecnt + 10) << '\n';
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("C. Copil Copac Draws Trees.in", "r", stdin);
  freopen("C. Copil Copac Draws Trees.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
